<?php
ini_set("memory_limit", "1024M");
require dirname(__FILE__) . '/../core/init.php';

/* Do NOT delete this comment */
/* 不要删除这段注释 */

$configs = array(
    'name' => 'haha.mx',
   // 'log_show' => true,
    'tasknum' => 1,
    //'save_running_state' => true,
    'domains' => array(
        'haha.mx',
        'www.haha.mx'
    ),
    'scan_urls' => array(
        'http://www.haha.mx/topic/1/new/'
    ),
    'list_url_regexes' => array(
        "http://www.haha.mx/topic/1/new/\d+"
    ),
    'content_url_regexes' => array(
        "",
    ),
    'max_try' => 5,

    'fields' => array(

        array(
            'name' => "imgfl",
            'selector' => "//div[contains(@class,'joke-main-content')]//a[1]",
            'required' => true,
        ),

    ),
);

$spider = new phpspider($configs);

$spider->on_handle_img = function ($fieldname, $img) {
    
 
    $regex = '/src="(https?:\/\/.*?)"/i';
        preg_match($regex, $img, $rs);
        if (!$rs) {
            return $img;
        }

        $url = $rs[1];
        $url = str_replace("small", "big", $url);
        $img = $url;

        $arr = parse_url($url);

        $file = basename($arr['path']);

        $image = file_get_contents($url);

        file_put_contents('images/'.$file, $image);
        return $img;
};

$spider->start();




 